/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package z.h.w.jar.arithmetic.method;

import java.util.List;

/**
 *
 * @author EnzoZhong @date 2011.09.18 @url
 * http://zh.wikipedia.org/wiki/%E5%B8%8C%E5%B0%94%E6%8E%92%E5%BA%8F
 */
public class SortShell implements SortMethodApi {

     /**
      *
      * @param <Type>
      * @param array
      * @return
      */
     @Override
     public synchronized <Type extends Comparable<? super Type>> Type[] sort ( Type[] array ) {
          int j;
          for ( int p = 1 ; p < array.length ; p ++ ) {
               Type temp = array[p];
               for ( j = p ; j > 0 && temp.compareTo ( array[j - 1] ) < 0 ; j -- ) {
                    array[j] = array[j - 1];
               }
               array[j] = temp;
          }
          return array;
     }

     /**
      *
      * @param <Type>
      * @param list
      * @return
      */
     @Override
     public synchronized <Type extends Comparable<? super Type>> List<Type> sort ( List<Type> list ) {
          int j;
          for ( int p = 1 ; p < list.size () ; p ++ ) {
               Type temp = list.get ( p );
               for ( j = p ; j > 0 && temp.compareTo ( list.get ( j - 1 ) ) < 0 ; j -- ) {
                    list.set ( j , list.get ( j - 1 ) );
               }
               list.set ( j , temp );
          }
          return list;
     }

}
